package cn.liontalk.demo;

/**
 * @author: 周哲
 * @package: cn.liontalk.demo
 * @description:
 * @date: 2019/1/26 13:36
 * @version: V1.0
 */
public class SynchronizedClassClass5 implements Runnable {

    static SynchronizedClassClass5 instance1 = new SynchronizedClassClass5();
    static SynchronizedClassClass5 instance2 = new SynchronizedClassClass5();

    public void run() {
        synchronized (SynchronizedClassClass5.class) {
            test();
        }
    }

    public   void test() {
        System.out.println("我是类锁第二种显示 :  代码块形式：" + Thread.currentThread().getName());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "：运行完成");
    }


    public static void main(String[] args) {
        Thread thread = new Thread(instance1);
        Thread thread1 = new Thread(instance2);

        thread.start();
        thread1.start();
        while (thread.isAlive() || thread1.isAlive()) {

        }
        System.out.println("Finished....");
    }
}
